#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int a[N],S[N];
int main()
{
	int n, w,maxx=0,ans=0;
	cin >> n >> w;
	for (int i = 0; i < n; i++)
	{
		int x, b;
		scanf("%d%d", &x, &b);
		a[x] = b;
		maxx = max(maxx, x);
	}
	for (int i = 1; i <= maxx; i++)
	{
		S[i] = S[i - 1] + a[i];
	}
	for (int i = w; i <= maxx; i++)
	{
		ans = max(ans, S[i] - S[i - w]);
	}
	cout << ans;
}